/*
 * @file yt_tab_bar_view
 * @Author: liuer
 * @Date: 2024/8/8 09:13
 * @LastModified: 2024-08-08 09:13
 * @LastModifiedBy: liuer
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yt_devops/components/app_permission/permission_widget.dart';
import 'package:yt_devops/components/app_permission/yt_tab_view_model.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/site_mains_elec_detail/keep_aliver_wrapper.dart';
import 'package:yt_devops/utils/func_utils.dart';

import '../log_utils.dart';

class YtTabBarView extends StatefulWidget {
  final int index;
  final List<YtTabViewModel> permissionGroups;
  const YtTabBarView(this.index, this.permissionGroups, {super.key});
  @override
  State<YtTabBarView> createState() => _YtTabBarViewState();
}

class _YtTabBarViewState extends State<YtTabBarView>
    with TickerProviderStateMixin {
  List<Widget> tabViewChildren = [];
  TabController? tabController;
  @override
  void initState() {
    // TODO: implement initState
    for (var element in widget.permissionGroups) {
      if (FuncUtils.isPassAuthority([element.permissionString]) &&
          element.isShow) {
        tabViewChildren.add(
          PermissionWidget(
              permissionStringList: [element.permissionString],
              child: KeepAliveWrapper(element.permissionWidget)),
        );
      }
    }
    tabController = TabController(length: tabViewChildren.length, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    tabController?.animateTo(widget.index);
    return TabBarView(
        controller: tabController,
        physics: const NeverScrollableScrollPhysics(), //禁止滑动
        children: tabViewChildren);
  }
}
